package com.qiwx.pigeon.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.annotation.Nullable;

import com.qiwx.pigeon.R;
import com.qiwx.pigeon.data.params.PigeonDeathParam;
import com.qiwx.pigeon.data.vo.CageRepairBean;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @description
 * @Author qiwx
 * @Date 2020-06-10 17:33
 * 鸽子死亡
 **/
public class PigeonDeathOptionView extends LinearLayout {
    
    @BindView(R.id.rb_death_wu)
    RadioButton rbDeathWu;
    @BindView(R.id.rb_death_1)
    RadioButton rbDeath1;
    @BindView(R.id.rb_death_2)
    RadioButton rbDeath2;
    @BindView(R.id.rb_death_3)
    RadioButton rbDeath3;
    @BindView(R.id.rb_death_4)
    RadioButton rbDeath4;
    @BindView(R.id.group_death_options)
    RadioGroup groupDeathOptions;
    @BindView(R.id.rb_change_cages)
    RadioButton rbChangeCages;
    @BindView(R.id.rb_no_change_cages)
    RadioButton rbNoChangeCages;
    @BindView(R.id.group_change_cages)
    RadioGroup groupChangeCages;
    @BindView(R.id.lin_death_options)
    LinearLayout linDeathOptions;
    @BindView(R.id.cb_remind)
    CheckBox cbRemind;

    public PigeonDeathOptionView(Context context) {
        this(context, null);
    }

    public PigeonDeathOptionView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public PigeonDeathOptionView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context) {
        LayoutInflater mInflater = LayoutInflater.from(context);
        View view = mInflater.inflate(R.layout.pigeon_death_option, null);
        ButterKnife.bind(this, view);
        addView(view);

    }

    public PigeonDeathParam getParam() {
        PigeonDeathParam param = new PigeonDeathParam();
        param.setDeath_amount(getDeathPigeonAmount());
        param.setIs_adjust(rbChangeCages.isChecked() ? 1 : 0);
        param.setIs_remind(cbRemind.isChecked() ? 1 : 0);
        return param;
    }

    //获取死亡鸽子选择的数量
    public int getDeathPigeonAmount() {
        if (rbDeath1.isChecked()) {
            return 1;
        } else if (rbDeath2.isChecked()) {
            return 2;
        } else if (rbDeath3.isChecked()) {
            return 3;
        } else if (rbDeath4.isChecked()) {
            return 4;
        }
        return 0;

    }


    //重置选项
    public void resetOptions() {
        rbDeath1.setChecked(true);
        rbChangeCages.setChecked(true);
    }
}
